# Title     : TODO
# Objective : TODO
# Created by: Administrator
# Created on: 2020/10/13 0013

pacman::p_load(dplyr, sqldf, lazyopt, stringr,magrittr)
#set.seed(100)
#a <- data.frame(namea = letters[1:6], value = runif(6))
#b <- data.frame(nameb = letters[3:10], age = runif(8, 15, 89))
#c <- data.frame(namec = letters[3:8], weight = runif(6, 150, 300))

#write.table(a, file = "E:/projects/R_draw_sc/test/table_change/data/a.txt", sep = "\t", na = "",row.names=FALSE)
#write.table(b, file = "E:/projects/R_draw_sc/test/table_change/data/b.txt", sep = "\t", na = "",row.names=FALSE)
#write.table(c, file = "E:/projects/R_draw_sc/test/table_change/data/c.txt", sep = "\t", na = "",row.names=FALSE)

#sqldf("select *from b left join a on namea=nameb") 左连接
#sqldf("select *from a,b where namea = nameb")  右连接


opt <- matrix(c(
  "inputfiles", "i", 2, "character", "", "",
  "outputfile", "o", 2, "character", "", "",
  "connect", "c", 1, "character", "left,right,in,all", "all"
), ncol = 6, byrow = TRUE) %>% lazyopt(arg = c(
  "-i", "E:/projects/R_draw_sc/test/table_change/data/a.txt;E:/projects/R_draw_sc/test/table_change/data/b.txt;E:/projects/R_draw_sc/test/table_change/data/c.txt",
  "-o", "ads"
))

filepaths <- (opt %$% str_split(inputfiles,";"))[[1]]

list <- list()
list[[1]] <- read.delim(filepaths[1])
list[[2]] <- read.delim(filepaths[2])
list[[3]] <- read.delim(filepaths[3])
names(list) <- letters[1:3]

sqldf("select *from list.a" )


